<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="资产名称" prop="assetName">
        <el-input
          v-model="queryParams.assetName"
          placeholder="请输入资产名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="资产状态" prop="assetStatus">
        <el-select v-model="queryParams.assetStatus" placeholder="请选择资产状态" clearable>
          <el-option
            v-for="dict in dict.type.asset_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="产权单位" prop="assetPropertyUnit">
        <el-select v-model="queryParams.assetPropertyUnit" placeholder="请选择产权单位" clearable>
          <el-option
            v-for="dict in dict.type.property_unit"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="资产地点" prop="assetAddressDistrict">
        <el-select v-model="queryParams.assetAddressDistrict" placeholder="请选择资产地点" clearable>
          <el-option
            v-for="area in areaList"
            :key="area.code"
            :label="area.name"
            :value="area.name"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="资产面积(㎡)" prop="assetArea">
        <el-select v-model="queryParams.assetArea" placeholder="请选择资产面积" clearable>
          <el-option
            v-for="dict in dict.type.screen_asset_area"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="资产类型" prop="assetHouseType">
        <el-select v-model="queryParams.assetHouseType" placeholder="请选择资产面积" clearable>
          <el-option
            v-for="dict in dict.type.asset_house_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:assetInfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:assetInfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:assetInfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:assetInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="assetInfoList" @selection-change="handleSelectionChange" @row-click="handleRowClick">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" width="60" type="index" align="center" />
      <el-table-column label="资产编号" align="center" width="140px">
        <template slot-scope="scope">
          {{scope.row.assetNumMaster}}<span v-if="scope.row.assetNumAttached">-{{scope.row.assetNumAttached}}</span>
        </template>
      </el-table-column>
      <el-table-column label="资产名称" width="280px" show-overflow-tooltip align="center" prop="assetName" >
      </el-table-column>
      <el-table-column label="资产地址" align="center"  show-overflow-tooltip  prop="assetAddress" >
        <template slot-scope="scope">
          {{scope.row.assetAddressDistrict}}{{scope.row.assetAddress}}
        </template>
      </el-table-column>
      <el-table-column label="资产面积(㎡)" align="center" width="140px" prop="assetArea" />
      <el-table-column label="账面原值(万元)" align="center" width="140px" prop="assetOriginalValue" />
      <el-table-column label="资产状态" width="140px" align="center" prop="assetStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.asset_status" :value="scope.row.assetStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" align="center" class-name="small-padding fixed-width" width="180px">
        <template slot-scope="scope">
          <el-button
            size="small"
            type="primary"
            title="修改"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:assetInfo:edit']"
          ></el-button>
          <el-button
            size="small"
            type="warning"
            title="复制"
            icon="el-icon-document-copy"
            @click="handleCopy(scope.row)"
            v-hasPermi="['business:assetInfo:add']"
          ></el-button>
          <el-button
            size="small"
            type="danger"
            title="删除"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:assetInfo:remove']"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listAssetInfo, getAssetInfo, delAssetInfo, addAssetInfo, updateAssetInfo } from "@/api/business/assetInfo";
import {proCityList} from '@/utils/china'
export default {
  name: "AssetInfo",
  dicts: ['asset_house_type', 'asset_status', 'screen_asset_area', 'property_unit', 'asset_house_type', 'age_limit'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 资产台账管理表格数据
      assetInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        assetNumMaster: null,
        assetNumAttached: null,
        assetName: null,
        assetCustomNum: null,
        assetAddressProvince: null,
        assetAddressCity: null,
        assetAddressDistrict: null,
        assetLon: null,
        assetLat: null,
        assetDoorNum: null,
        assetUnitNum: null,
        assetRoomNum: null,
        assetHouseType: null,
        assetArea: null,
        assetOriginalValue: null,
        assetEstablishDate: null,
        assetOwnershipLength: null,
        assetPropertyUnit: null,
        assetStatus: null,
        assetImg: null,
        assetRemark: null,
        assetIsDelete: null,
        assetAddress: null
      },
      proCityList: proCityList,
      cityLsit: [],
      areaList: [],
    };
  },
  created() {
    this.getCity()
    this.getList();
    setTimeout(this.getArea())
  },
  activated() {
    this.getList();
  },
  methods: {
    getCity() {
      this.cityLsit = this.proCityList.find(i => i.name == '辽宁省').children
    },
    getArea() {
      this.areaList = this.cityLsit.find(i => i.name == '沈阳市').children
    },
    /** 查询资产台账管理列表 */
    getList() {
      this.loading = true;
      listAssetInfo(this.queryParams).then(response => {
        this.assetInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        assetId: null,
        assetNumMaster: null,
        assetNumAttached: null,
        assetName: null,
        assetCustomNum: null,
        assetAddressProvince: null,
        assetAddressCity: null,
        assetAddressDistrict: null,
        assetLon: null,
        assetLat: null,
        assetDoorNum: null,
        assetUnitNum: null,
        assetRoomNum: null,
        assetHouseType: null,
        assetArea: null,
        assetOriginalValue: null,
        assetEstablishDate: null,
        assetOwnershipLength: null,
        assetPropertyUnit: null,
        assetStatus: null,
        assetIsDelete: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.assetId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },

    // 行点击
    handleRowClick(row, column, event) {
      if(column.label != '操作') {
        this.$router.push('/AssetLedger/asset-info/' + row.assetId)
      }
    },
    /** 新增按钮操作 */
    handleAdd() {
      // this.reset();
      // this.open = true;
      // this.title = "添加资产台账管理";
      this.$router.push('/AssetLedger/asset-edit/add')
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const assetId = row.assetId || this.ids
      this.$router.push('/AssetLedger/asset-edit/' + assetId)
    },
    /** 复制按钮操作 */
    handleCopy(row) {
      const assetId = row.assetId || this.ids
      this.$router.push('/AssetLedger/asset-edit/copy/' + assetId)
    },
    /** 复跳转详情 */
    showInfo({assetId}) {
      this.$router.push('/AssetLedger/asset-info/' + assetId)
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const assetIds = row.assetId || this.ids;
      this.$modal.confirm('是否确认删除资产台账管理编号为"' + assetIds + '"的数据项？').then(function() {
        return delAssetInfo(assetIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/assetInfo/export', {
        ...this.queryParams
      }, `assetInfo_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
